/**
************************************************************
* @file         gizwits_product.c
* @brief        Gizwits control protocol processing, and platform-related       hardware initialization 
* @author       Gizwits
* @date         2017-07-19
* @version      V03030000
* @copyright    Gizwits
* 
* @note         机智云.只为智能硬件而生
*               Gizwits Smart Cloud  for Smart Products
*               链接|增值ֵ|开放|中立|安全|自有|自由|生态
*               www.gizwits.com
*
***********************************************************/

#include <stdio.h>
#include <string.h>
#include "gizwits_product.h"
#include "common.h"
#include "usart3.h"
#include "head.h"
static uint32_t timerMsCount;
uint8_t aRxBuffer;

/** User area the current device state structure*/
dataPoint_t currentDataPoint;
//extern keysTypedef_t keys;

//extern TIM_HandleTypeDef htim2;
//extern UART_HandleTypeDef huart1;
//extern UART_HandleTypeDef huart2;
/******************/
extern u8 nicewater;
extern u8 vice_state;
extern u16  TIME;
extern u8 STATE;
extern 	u8 speed;
extern u8 chu1;
extern u8 chu2;
extern u8 chu3;
extern u8 chu4;
extern u8 chu5;
extern u8 chu6;
extern u8 chu7;
extern u8 chu8;
extern u8 chu9;
extern u8 chu10;
extern u8 chu11;
extern u8 chu12;
extern u8 zstate;
extern u8 windows;
extern	u8 *pname;
extern u8 zchuk;
extern u8 zchub;
extern u8 renew;
extern u8 rchuk;
extern u8 rchub;
extern u8 wchuk;
extern u8 wchub;
extern u16 ztime;
extern u8 zspeed;
extern u8 maxtemp;
extern u8 waterstate;
extern u8 mianstate;
extern u8 sure;
extern u8 table;
extern u8 recover[10];
extern u8 rtable;
extern u8 windows_admin;
extern u8 rtable;
extern u8 windows_admin;
extern u8 ychuk;
extern u8 ychub;
extern u8 ystate;
extern u8 windows_yamian;
extern u8 yastate;
extern u8 yachuk;
extern u8 yachub;
extern u8 yrenew;
extern u8 yrtable;
extern u16 ytime;
extern u8 yspeed;
extern u8 ysure;
extern u8 skip;
extern u8 skip_time;
extern u8 ysspeed;
extern u8 onlystart;
extern u8 onestart;
extern u8 kind;
extern u8 kindboth[2];
extern u8 miantime;
extern u8 mianstate;
/**@} */
/**@name Gizwits User Interface
* @{
*/

/**
* @brief Event handling interface

* Description:

* 1. Users can customize the changes in WiFi module status

* 2. Users can add data points in the function of event processing logic, such as calling the relevant hardware peripherals operating interface

* @param [in] info: event queue
* @param [in] data: protocol data
* @param [in] len: protocol data length
* @return NULL
* @ref gizwits_protocol.h
*/
int8_t gizwitsEventProcess(eventInfo_t *info, uint8_t *gizdata, uint32_t len)
{
  uint8_t i = 0;
  dataPoint_t *dataPointPtr = (dataPoint_t *)gizdata;
  moduleStatusInfo_t *wifiData = (moduleStatusInfo_t *)gizdata;
  protocolTime_t *ptime = (protocolTime_t *)gizdata;
  
#if MODULE_TYPE
  gprsInfo_t *gprsInfoData = (gprsInfo_t *)gizdata;
#else
  moduleInfo_t *ptModuleInfo = (moduleInfo_t *)gizdata;
#endif

  if((NULL == info) || (NULL == gizdata))
  {
    return -1;
  }

 for(i=0; i<info->num; i++)
  {
    switch(info->event[i])
    {
      case EVENT_LED1:
        currentDataPoint.valueLED1 = dataPointPtr->valueLED1;
        GIZWITS_LOG("Evt: EVENT_LED1 %d \n", currentDataPoint.valueLED1);
        if(0x01 == currentDataPoint.valueLED1)
        {
         LED0=0;
        }
        else
        {
          LED0=1; 
        }
        break;
      case EVENT_LED2:
        currentDataPoint.valueLED2 = dataPointPtr->valueLED2;
        GIZWITS_LOG("Evt: EVENT_LED2 %d \n", currentDataPoint.valueLED2);
        if(0x01 == currentDataPoint.valueLED2)
        {
          LED1=0;
        }
        else
        {
					LED1=1;
        }
        break;
      case EVENT_LED3:
        currentDataPoint.valueLED3 = dataPointPtr->valueLED3;
        GIZWITS_LOG("Evt: EVENT_LED3 %d \n", currentDataPoint.valueLED3);
        if(0x01 == currentDataPoint.valueLED3)
        {
         LED2=0;
        }
        else
        {
          LED2=1;
        }
        break;
      case EVENT_SheE:
        currentDataPoint.valueSheE = dataPointPtr->valueSheE;
        GIZWITS_LOG("Evt: EVENT_SheE %d \n", currentDataPoint.valueSheE);
        if(0x01 == currentDataPoint.valueSheE)
        {
          	windows_admin=1;
            recover[4]=1;
        }
        else
        {
          	windows_admin=1;
            recover[4]=1;
        }
        break;
      case EVENT_SyaE:
        currentDataPoint.valueSyaE = dataPointPtr->valueSyaE;
        GIZWITS_LOG("Evt: EVENT_SyaE %d \n", currentDataPoint.valueSyaE);
        if(0x01 == currentDataPoint.valueSyaE)
        {
            windows_admin=2;
                recover[5]=1;
        }
        else
        {
            windows_admin=2;
                recover[5]=1;
        }
        break;
      case EVENT_SonestartE:
        currentDataPoint.valueSonestartE = dataPointPtr->valueSonestartE;
        GIZWITS_LOG("Evt: EVENT_SonestartE %d \n", currentDataPoint.valueSonestartE);
        if(0x01 == currentDataPoint.valueSonestartE)
        {
          windows_admin=1;
					nicewater=0;
		    	recover[0]=1;
				 onestart=1;
				 onlystart=0;
									if(kind==0)
					miantime=20;
				else
									{
					if(kindboth[kind-1]==1)
						miantime=10;
					else
						miantime=20;
				}
        }
        else
        {
          windows_admin=1;
					nicewater=0;
		    	recover[0]=1;
				 onestart=1;
				 onlystart=0;
									if(kind==0)
					miantime=20;
				else
								{
					if(kindboth[kind-1]==1)
						miantime=10;
					else
						miantime=20;
				}
        }
        break;
      case EVENT_SkindE:
        currentDataPoint.valueSkindE = dataPointPtr->valueSkindE;
        GIZWITS_LOG("Evt: EVENT_SkindE %d \n", currentDataPoint.valueSkindE);
        if(0x01 == currentDataPoint.valueSkindE)
        {
         				windows_admin=3;
				LCD_Clear(WHITE);
				ai_load_picfile(pname,0,0,lcd_width,lcd_height,1);
        }
        else
        {
         				windows_admin=3;
				LCD_Clear(WHITE);
				ai_load_picfile(pname,0,0,lcd_width,lcd_height,1);  
        }
        break;
		 case EVENT_kind:
        currentDataPoint.valuekind = dataPointPtr->valuekind;
        GIZWITS_LOG("Evt:EVENT_kind %d\n",currentDataPoint.valuekind);
        //user handle
        break;
      case EVENT_wan:
        currentDataPoint.valuewan = dataPointPtr->valuewan;
        GIZWITS_LOG("Evt:EVENT_wan %d\n",currentDataPoint.valuewan);
        //user handle
        break;
      case EVENT_SwindowE:
        currentDataPoint.valueSwindowE = dataPointPtr->valueSwindowE;
        GIZWITS_LOG("Evt: EVENT_SwindowE %d \n", currentDataPoint.valueSwindowE);
        if(0x01 == currentDataPoint.valueSwindowE)
        {
          				windows=0;
				windows_admin=0;
				LCD_Clear(WHITE);
				ai_load_picfile(pname,0,0,lcd_width,lcd_height,1);
        }
        else
        {
        				windows=0;
				windows_admin=0;
				LCD_Clear(WHITE);
				ai_load_picfile(pname,0,0,lcd_width,lcd_height,1); 
        }
        break;
      case EVENT_SautoE:
        currentDataPoint.valueSautoE = dataPointPtr->valueSautoE;
        GIZWITS_LOG("Evt: EVENT_SautoE %d \n", currentDataPoint.valueSautoE);
        if(0x01 == currentDataPoint.valueSautoE)
        {
          recover[0]=1;
        }
        else
        {
          recover[0]=1;
        }
        break;
				//自动和面调试
      case EVENT_SaustartE:
        currentDataPoint.valueSaustartE = dataPointPtr->valueSaustartE;
        GIZWITS_LOG("Evt: EVENT_SaustartE %d \n", currentDataPoint.valueSaustartE);
        if(0x01 == currentDataPoint.valueSaustartE)
        {
                if(windows==2)          //自动一体化开始
                {
							vice_state=1;
									nicewater=0;
                    zstate=1;
                    zchuk=1;
                    zchub=0;
													if(kind==0)
					miantime=20;
				else
							{
					if(kindboth[kind-1]==1)
						miantime=10;
					else
						miantime=20;
				}
									  onlystart=0;
                }
        }
        else
        {
                if(windows==2)          //自动一体化开始
                {
							vice_state=1;
									nicewater=0;
                    zstate=1;
                    zchuk=1;
                    zchub=0;
													if(kind==0)
					miantime=20;
				else
									{
					if(kindboth[kind-1]==1)
						miantime=10;
					else
						miantime=20;
				}
									  onlystart=0;
                }
        }
        break;
      case EVENT_SonlystartE:
        currentDataPoint.valueSonlystartE = dataPointPtr->valueSonlystartE;
        GIZWITS_LOG("Evt: EVENT_SonlystartE %d \n", currentDataPoint.valueSonlystartE);
        if(0x01 == currentDataPoint.valueSonlystartE)
        {
                if(windows==2)          //自动和面开始
                {
									nicewater=0;
									vice_state=1;
                    zstate=1;
                    zchuk=1;
                    zchub=0;
													if(kind==0)
					miantime=20;
				else
									{
					if(kindboth[kind-1]==1)
						miantime=10;
					else
						miantime=20;
				}
									  onlystart=1;
                }
        }
        else
        {
                if(windows==2)          //自动和面开始
                {
									nicewater=0;
									vice_state=1;
                    zstate=1;
                    zchuk=1;
                    zchub=0;
													if(kind==0)
					miantime=20;
				else
									{
					if(kindboth[kind-1]==1)
						miantime=10;
					else
						miantime=20;
				}
									  onlystart=1;
                }
        }
        break;
      case EVENT_SaustopE:
        currentDataPoint.valueSaustopE = dataPointPtr->valueSaustopE;
        GIZWITS_LOG("Evt: EVENT_SaustopE %d \n", currentDataPoint.valueSaustopE);
        if(0x01 == currentDataPoint.valueSaustopE)
        {
                if(windows==2)			//自动暂停
                {
                    zstate=0;
                    zchuk=0;
                    zchub=1;
                }
        }
        else
        {
                if(windows==2)			//自动暂停
                {
                    zstate=0;
                    zchuk=0;
                    zchub=1;
                }
        }
        break;
      case EVENT_SaurestE:
        currentDataPoint.valueSaurestE = dataPointPtr->valueSaurestE;
        GIZWITS_LOG("Evt: EVENT_SaurestE %d \n", currentDataPoint.valueSaurestE);
        if(0x01 == currentDataPoint.valueSaurestE)
        {
                          if(windows==2)       //自动刷新
                {
                    renew=1;
                }
        }
        else
        {
                       if(windows==2)       //自动刷新
                {
                    renew=1;
                }
        }
        break;
      case EVENT_SmanualE:
        currentDataPoint.valueSmanualE = dataPointPtr->valueSmanualE;
        GIZWITS_LOG("Evt: EVENT_SmanualE %d \n", currentDataPoint.valueSmanualE);
        if(0x01 == currentDataPoint.valueSmanualE)
        {
                         recover[1]=1;
        }
        else
        {
                 recover[1]=1;
        }
        break;
      case EVENT_ScloseautoE:
        currentDataPoint.valueScloseautoE = dataPointPtr->valueScloseautoE;
        GIZWITS_LOG("Evt: EVENT_ScloseautoE %d \n", currentDataPoint.valueScloseautoE);
        if(0x01 == currentDataPoint.valueScloseautoE)
        {
                 recover[4]=1;
        }
        else
        {
                recover[4]=1;
        }
        break;
      case EVENT_SmodifyE:
        currentDataPoint.valueSmodifyE = dataPointPtr->valueSmodifyE;
        GIZWITS_LOG("Evt: EVENT_SmodifyE %d \n", currentDataPoint.valueSmodifyE);
        if(0x01 == currentDataPoint.valueSmodifyE)
        {
          recover[2]=1;
        }
        else
        {
          recover[2]=1;
        }
        break;
      case EVENT_SrestE:
        currentDataPoint.valueSrestE = dataPointPtr->valueSrestE;
        GIZWITS_LOG("Evt: EVENT_SrestE %d \n", currentDataPoint.valueSrestE);
        if(0x01 == currentDataPoint.valueSrestE)
        {
           recover[3]=1;
                if(rtable==1)
                    rtable=0;
                else
                    rtable=1;
        }
        else
        {
           recover[3]=1;
                if(rtable==1)
                    rtable=0;
                else
                    rtable=1;
        }
        break;
      case EVENT_SmstartE:
        currentDataPoint.valueSmstartE = dataPointPtr->valueSmstartE;
        GIZWITS_LOG("Evt: EVENT_SmstartE %d \n", currentDataPoint.valueSmstartE);
        if(0x01 == currentDataPoint.valueSmstartE)
        {
                         if(windows==1) {
                    STATE=1;
                    zchuk=1;
                    zchub=0;
                }
        }
        else
        {
                         if(windows==1) {
                    STATE=1;
                    zchuk=1;
                    zchub=0;
                }
        }
        break;
      case EVENT_SmstopE:
        currentDataPoint.valueSmstopE = dataPointPtr->valueSmstopE;
        GIZWITS_LOG("Evt: EVENT_SmstopE %d \n", currentDataPoint.valueSmstopE);
        if(0x01 == currentDataPoint.valueSmstopE)
        {
          if(windows==1) {
                    STATE=0;
                    zchuk=0;
                    zchub=1;
                }
        }
        else
        {
          if(windows==1) {
                    STATE=0;
                    zchuk=0;
                    zchub=1;
                }
        }
        break;
      case EVENT_StstartE:
        currentDataPoint.valueStstartE = dataPointPtr->valueStstartE;
        GIZWITS_LOG("Evt: EVENT_StstartE %d \n", currentDataPoint.valueStstartE);
        if(0x01 == currentDataPoint.valueStstartE)
        {
          if(windows==1) {
                    rchuk=1;
                    rchub=0;
                }
        }
        else
        {
          if(windows==1) {
                    rchuk=1;
                    rchub=0;
                }
        }
        break;
      case EVENT_StstopE:
        currentDataPoint.valueStstopE = dataPointPtr->valueStstopE;
        GIZWITS_LOG("Evt: EVENT_StstopE %d \n", currentDataPoint.valueStstopE);
        if(0x01 == currentDataPoint.valueStstopE)
        {
           if(windows==1) {
                    rchuk=0;
                    rchub=1;
                }
        }
        else
        {
           if(windows==1) {
                    rchuk=0;
                    rchub=1;
                }
        }
        break;
      case EVENT_SwstartE:
        currentDataPoint.valueSwstartE = dataPointPtr->valueSwstartE;
        GIZWITS_LOG("Evt: EVENT_SwstartE %d \n", currentDataPoint.valueSwstartE);
        if(0x01 == currentDataPoint.valueSwstartE)
        {
          if(windows==1) {
                    wchuk=1;
                    wchub=0;
                }
        }
        else
        {
         if(windows==1) {
                    wchuk=1;
                    wchub=0;
                }
        }
        break;
      case EVENT_SwstopE:
        currentDataPoint.valueSwstopE = dataPointPtr->valueSwstopE;
        GIZWITS_LOG("Evt: EVENT_SwstopE %d \n", currentDataPoint.valueSwstopE);
        if(0x01 == currentDataPoint.valueSwstopE)
        {
            if(windows==1) {
                    wchuk=0;
                    wchub=1;
                }
        }
        else
        {
           if(windows==1) {
                    wchuk=0;
                    wchub=1;
                }
        }
        break;
      case EVENT_StimejE:
        currentDataPoint.valueStimejE = dataPointPtr->valueStimejE;
        GIZWITS_LOG("Evt: EVENT_StimejE %d \n", currentDataPoint.valueStimejE);
        if(0x01 == currentDataPoint.valueStimejE)
        {
         if(windows==1) {
                    TIME=TIME+5;
                }
        }
        else
        {
         if(windows==1) {
                    TIME=TIME+5;
                }
        }
        break;
      case EVENT_StimejiE:
        currentDataPoint.valueStimejiE = dataPointPtr->valueStimejiE;
        GIZWITS_LOG("Evt: EVENT_StimejiE %d \n", currentDataPoint.valueStimejiE);
        if(0x01 == currentDataPoint.valueStimejiE)
        {
         if(windows==1) {
                    if(TIME-5<=0)
                        TIME=0;
                    else
                        TIME=TIME-5;
                }
        }
        else
        {
          if(windows==1) {
                    if(TIME-5<=0)
                        TIME=0;
                    else
                        TIME=TIME-5;
                }
        }
        break;
      case EVENT_SspeedjE:
        currentDataPoint.valueSspeedjE = dataPointPtr->valueSspeedjE;
        GIZWITS_LOG("Evt: EVENT_SspeedjE %d \n", currentDataPoint.valueSspeedjE);
        if(0x01 == currentDataPoint.valueSspeedjE)
        {
          if(windows==1) {
                    if(speed==5)
                        speed=5;
                    else
                        speed=speed+1;
                }

        }
        else
        {
          if(windows==1) {
                    if(speed==5)
                        speed=5;
                    else
                        speed=speed+1;
                }

        }
        break;
      case EVENT_SspeedjiE:
        currentDataPoint.valueSspeedjiE = dataPointPtr->valueSspeedjiE;
        GIZWITS_LOG("Evt: EVENT_SspeedjiE %d \n", currentDataPoint.valueSspeedjiE);
        if(0x01 == currentDataPoint.valueSspeedjiE)
        {
          if(windows==1) {
                    if(speed==0)
                        speed=0;
                    else
                        speed=speed-1;
                }
        }
        else
        {
          if(windows==1) {
                    if(speed==0)
                        speed=0;
                    else
                        speed=speed-1;
                }
        }
        break;
								//修改和面配置
      case EVENT_StempjE:
        currentDataPoint.valueStempjE = dataPointPtr->valueStempjE;
        GIZWITS_LOG("Evt: EVENT_StempjE %d \n", currentDataPoint.valueStempjE);
        if(0x01 == currentDataPoint.valueStempjE)
        {
             if(windows==3) {
                    maxtemp++;
                }

        }
        else
        {
            if(windows==3) {
                    maxtemp++;
                }

        }
        break;
      case EVENT_StempjiE:
        currentDataPoint.valueStempjiE = dataPointPtr->valueStempjiE;
        GIZWITS_LOG("Evt: EVENT_StempjiE %d \n", currentDataPoint.valueStempjiE);
        if(0x01 == currentDataPoint.valueStempjiE)
        {
            if(windows==3) {
                    if(maxtemp-1<=0)
                        maxtemp=0;
                    else
                        maxtemp--;
                }
        }
        else
        {
            if(windows==3) {
                    if(maxtemp-1<=0)
                        maxtemp=0;
                    else
                        maxtemp--;
                }
        }
        break;
				//面粉+
      case EVENT_SmaxmianE:
        currentDataPoint.valueSmaxmianE = dataPointPtr->valueSmaxmianE;
        GIZWITS_LOG("Evt: EVENT_SmaxmianE %d \n", currentDataPoint.valueSmaxmianE);
        if(0x01 == currentDataPoint.valueSmaxmianE)
        {
          if(++mianstate>=3) mianstate=2;//user handle
        }
        else
        {
          if(++mianstate>=3) mianstate=2;//user handle    
        }
        break;
      case EVENT_SminmianE:
        currentDataPoint.valueSminmianE = dataPointPtr->valueSminmianE;
        GIZWITS_LOG("Evt: EVENT_SminmianE %d \n", currentDataPoint.valueSminmianE);
        if(0x01 == currentDataPoint.valueSminmianE)
        {
          if(mianstate-1<=0)
					mianstate=1;
				else
					mianstate--;//user handle
        }
        else
        {
          if(mianstate-1<=0)
					mianstate=1;
				else
					mianstate--;//user handle    
        }
        break;
      case EVENT_SautimejE:
        currentDataPoint.valueSautimejE = dataPointPtr->valueSautimejE;
        GIZWITS_LOG("Evt: EVENT_SautimejE %d \n", currentDataPoint.valueSautimejE);
        if(0x01 == currentDataPoint.valueSautimejE)
        {
           if(windows==3) {
                    ztime=ztime+5;
                }
        }
        else
        {
            if(windows==3) {
                    ztime=ztime+5;
                }
        }
        break;
      case EVENT_SautimejiE:
        currentDataPoint.valueSautimejiE = dataPointPtr->valueSautimejiE;
        GIZWITS_LOG("Evt: EVENT_SautimejiE %d \n", currentDataPoint.valueSautimejiE);
        if(0x01 == currentDataPoint.valueSautimejiE)
        {
            if(windows==3) {
                    if(ztime-5<=0)
                        ztime=0;
                    else
                        ztime=ztime-5;
                }
        }
        else
        {
            if(windows==3) {
                    if(ztime-5<=0)
                        ztime=0;
                    else
                        ztime=ztime-5;
                }
        }
        break;
      case EVENT_SauspeedjE:
        currentDataPoint.valueSauspeedjE = dataPointPtr->valueSauspeedjE;
        GIZWITS_LOG("Evt: EVENT_SauspeedjE %d \n", currentDataPoint.valueSauspeedjE);
        if(0x01 == currentDataPoint.valueSauspeedjE)
        {
          if(windows==3) {
                    if(zspeed==5)
                        zspeed=5;
                    else
                        zspeed=zspeed+1;
                }

        }
        else
        {
          if(windows==3) {
                    if(zspeed==5)
                        zspeed=5;
                    else
                        zspeed=zspeed+1;
                }

        }
        break;
      case EVENT_SauspeedjiE:
        currentDataPoint.valueSauspeedjiE = dataPointPtr->valueSauspeedjiE;
        GIZWITS_LOG("Evt: EVENT_SauspeedjiE %d \n", currentDataPoint.valueSauspeedjiE);
        if(0x01 == currentDataPoint.valueSauspeedjiE)
        {
          if(windows==3) {
                    if(zspeed==0)
                        zspeed=0;
                    else
                        zspeed=zspeed-1;
                }
        }
        else
        {
          if(windows==3) {
                    if(zspeed==0)
                        zspeed=0;
                    else
                        zspeed=zspeed-1;
                }
        }
        break;
      case EVENT_SmensureE:
        currentDataPoint.valueSmensureE = dataPointPtr->valueSmensureE;
        GIZWITS_LOG("Evt: EVENT_SmensureE %d \n", currentDataPoint.valueSmensureE);
        if(0x01 == currentDataPoint.valueSmensureE)
        {
          if(windows==3) {
                    sure=1;
                    if(table==1)
                        table=0;
                    else
                        table=1;
                }
        }
        else
        {
          if(windows==3) {
                    sure=1;
                    if(table==1)
                        table=0;
                    else
                        table=1;
                }
        }
        break;
      case EVENT_SyautoE:
        currentDataPoint.valueSyautoE = dataPointPtr->valueSyautoE;
        GIZWITS_LOG("Evt: EVENT_SyautoE %d \n", currentDataPoint.valueSyautoE);
        if(0x01 == currentDataPoint.valueSyautoE)
        {
           recover[6]=1;
        }
        else
        {
           recover[6]=1;
        }
        break;
      case EVENT_SycloseautoE:
        currentDataPoint.valueSycloseautoE = dataPointPtr->valueSycloseautoE;
        GIZWITS_LOG("Evt: EVENT_SycloseautoE %d \n", currentDataPoint.valueSycloseautoE);
        if(0x01 == currentDataPoint.valueSycloseautoE)
        {
        recover[5]=1;
        }
        else
        {
          recover[5]=1;
        }
        break;
      case EVENT_SymanualE:
        currentDataPoint.valueSymanualE = dataPointPtr->valueSymanualE;
        GIZWITS_LOG("Evt: EVENT_SymanualE %d \n", currentDataPoint.valueSymanualE);
        if(0x01 == currentDataPoint.valueSymanualE)
        {
           recover[7]=1;
        }
        else
        {
          recover[7]=1;
        }
        break;
      case EVENT_SymodifyE:
        currentDataPoint.valueSymodifyE = dataPointPtr->valueSymodifyE;
        GIZWITS_LOG("Evt: EVENT_SymodifyE %d \n", currentDataPoint.valueSymodifyE);
        if(0x01 == currentDataPoint.valueSymodifyE)
        {
         recover[8]=1;
        }
        else
        {
          recover[8]=1;
        }
        break;
      case EVENT_SyrestE:
        currentDataPoint.valueSyrestE = dataPointPtr->valueSyrestE;
        GIZWITS_LOG("Evt: EVENT_SyrestE %d \n", currentDataPoint.valueSyrestE);
        if(0x01 == currentDataPoint.valueSyrestE)
        {
           recover[9]=1;
                if(yrtable==1)
                    yrtable=0;
                else
                    yrtable=1;
        }
        else
        {
            recover[9]=1;
                if(yrtable==1)
                    yrtable=0;
                else
                    yrtable=1;
        }
        break;
      case EVENT_SyaustartE:
        currentDataPoint.valueSyaustartE = dataPointPtr->valueSyaustartE;
        GIZWITS_LOG("Evt: EVENT_SyaustartE %d \n", currentDataPoint.valueSyaustartE);
        if(0x01 == currentDataPoint.valueSyaustartE)
        {
           if(windows_yamian==1)          //自动开始
                {
                    yastate=1;
                    yachuk=1;
                    yachub=0;
                }
        }
        else
        {
            if(windows_yamian==1)          //自动开始
                {
                    yastate=1;
                    yachuk=1;
                    yachub=0;
                }
        }
        break;
      case EVENT_SyaustopE:
        currentDataPoint.valueSyaustopE = dataPointPtr->valueSyaustopE;
        GIZWITS_LOG("Evt: EVENT_SyaustopE %d \n", currentDataPoint.valueSyaustopE);
        if(0x01 == currentDataPoint.valueSyaustopE)
        {
          if(windows_yamian==1)			//自动暂停
                {
                    yastate=0;
                    yachuk=0;
                    yachub=1;
                }
        }
        else
        {
          if(windows_yamian==1)			//自动暂停
                {
                    yastate=0;
                    yachuk=0;
                    yachub=1;
                }
        }
        break;
      case EVENT_SyaurestE:
        currentDataPoint.valueSyaurestE = dataPointPtr->valueSyaurestE;
        GIZWITS_LOG("Evt: EVENT_SyaurestE %d \n", currentDataPoint.valueSyaurestE);
        if(0x01 == currentDataPoint.valueSyaurestE)
        {
          if(windows_yamian==1)       //自动刷新
                {
                    yrenew=1;
                }
        }
        else
        {
          if(windows_yamian==1)       //自动刷新
                {
                    yrenew=1;
                }
        }
        break;
      case EVENT_SymstartE:
        currentDataPoint.valueSymstartE = dataPointPtr->valueSymstartE;
        GIZWITS_LOG("Evt: EVENT_SymstartE %d \n", currentDataPoint.valueSymstartE);
        if(0x01 == currentDataPoint.valueSymstartE)
        {
           if(windows_yamian==2) {
                    ystate=1;
                    ychuk=1;
                    ychub=0;
                }
        }
        else
        {
           if(windows_yamian==2) {
                    ystate=1;
                    ychuk=1;
                    ychub=0;
                }
        }
        break;
      case EVENT_SymstopE:
        currentDataPoint.valueSymstopE = dataPointPtr->valueSymstopE;
        GIZWITS_LOG("Evt: EVENT_SymstopE %d \n", currentDataPoint.valueSymstopE);
        if(0x01 == currentDataPoint.valueSymstopE)
        {
           if(windows_yamian==2) {
                    ystate=0;
                    ychuk=0;
                    ychub=1;
                }
        }
        else
        {
          if(windows_yamian==2) {
                    ystate=0;
                    ychuk=0;
                    ychub=1;
                }
        }
        break;
      case EVENT_SyspeedjE:
        currentDataPoint.valueSyspeedjE = dataPointPtr->valueSyspeedjE;
        GIZWITS_LOG("Evt: EVENT_SyspeedjE %d \n", currentDataPoint.valueSyspeedjE);
        if(0x01 == currentDataPoint.valueSyspeedjE)
        {
          if(windows_yamian==2) {
                    if(ysspeed==5)
                        ysspeed=5;
                    else
                        ysspeed=ysspeed+1;
                }
        }
        else
        {
          if(windows_yamian==2) {
                    if(ysspeed==5)
                        ysspeed=5;
                    else
                        ysspeed=ysspeed+1;
                }
        }
        break;
      case EVENT_SyspeedjiE:
        currentDataPoint.valueSyspeedjiE = dataPointPtr->valueSyspeedjiE;
        GIZWITS_LOG("Evt: EVENT_SyspeedjiE %d \n", currentDataPoint.valueSyspeedjiE);
        if(0x01 == currentDataPoint.valueSyspeedjiE)
        {
          if(windows_yamian==2) {
                    if(ysspeed==0)
                        ysspeed=0;
                    else
                        ysspeed=ysspeed-1;
                }
        }
        else
        {
          if(windows_yamian==2) {
                    if(ysspeed==0)
                        ysspeed=0;
                    else
                        ysspeed=ysspeed-1;
                }
        }
        break;
      case EVENT_SyautimejE:
        currentDataPoint.valueSyautimejE = dataPointPtr->valueSyautimejE;
        GIZWITS_LOG("Evt: EVENT_SyautimejE %d \n", currentDataPoint.valueSyautimejE);
        if(0x01 == currentDataPoint.valueSyautimejE)
        {
            if(windows_yamian==3) {
                    ytime=ytime+5;
                }

        }
        else
        {
            if(windows_yamian==3) {
                    ytime=ytime+5;
                }

        }
        break;
      case EVENT_SyautimejiE:
        currentDataPoint.valueSyautimejiE = dataPointPtr->valueSyautimejiE;
        GIZWITS_LOG("Evt: EVENT_SyautimejiE %d \n", currentDataPoint.valueSyautimejiE);
        if(0x01 == currentDataPoint.valueSyautimejiE)
        {
          if(windows_yamian==3) {
                    if(ytime-5<=0)
                        ytime=0;
                    else
                        ytime=ytime-5;
                }
        }
        else
        {
         if(windows_yamian==3) {
                    if(ytime-5<=0)
                        ytime=0;
                    else
                        ytime=ytime-5;
                }
        }
        break;
      case EVENT_SyauspeedjE:
        currentDataPoint.valueSyauspeedjE = dataPointPtr->valueSyauspeedjE;
        GIZWITS_LOG("Evt: EVENT_SyauspeedjE %d \n", currentDataPoint.valueSyauspeedjE);
        if(0x01 == currentDataPoint.valueSyauspeedjE)
        {
          if(windows_yamian==3) {
                    if(yspeed==5)
                        yspeed=5;
                    else
                        yspeed=yspeed+1;
                }
        }
        else
        {
         if(windows_yamian==3) {
                    if(yspeed==5)
                        yspeed=5;
                    else
                        yspeed=yspeed+1;
                }
        }
        break;
      case EVENT_SyauspeedjiE:
        currentDataPoint.valueSyauspeedjiE = dataPointPtr->valueSyauspeedjiE;
        GIZWITS_LOG("Evt: EVENT_SyauspeedjiE %d \n", currentDataPoint.valueSyauspeedjiE);
        if(0x01 == currentDataPoint.valueSyauspeedjiE)
        {
          if(windows_yamian==3) {
                    if(yspeed==0)
                        yspeed=0;
                    else
                        yspeed=yspeed-1;
                }

        }
        else
        {
          if(windows_yamian==3) {
                    if(yspeed==0)
                        yspeed=0;
                    else
                        yspeed=yspeed-1;
                }

        }
        break;
      case EVENT_SymensureE:
        currentDataPoint.valueSymensureE = dataPointPtr->valueSymensureE;
        GIZWITS_LOG("Evt: EVENT_SymensureE %d \n", currentDataPoint.valueSymensureE);
        if(0x01 == currentDataPoint.valueSymensureE)
        {
          if(windows_yamian==3) {
                    ysure=1;
                    if(table==1)
                        table=0;
                    else
                        table=1;
                }
        }
        else
        {
          if(windows_yamian==3) {
                    ysure=1;
                    if(table==1)
                        table=0;
                    else
                        table=1;
                }
        }
        break;
      case EVENT_SmaxwaterE:
        currentDataPoint.valueSmaxwaterE = dataPointPtr->valueSmaxwaterE;
        GIZWITS_LOG("Evt: EVENT_SmaxwaterE %d \n", currentDataPoint.valueSmaxwaterE);
        if(0x01 == currentDataPoint.valueSmaxwaterE)
        {
         if(++waterstate>=3) waterstate=2; //user handle
        }
        else
        {
          if(++waterstate>=3) waterstate=2;//user handle    
        }
        break;
      case EVENT_SminwaterE:
        currentDataPoint.valueSminwaterE = dataPointPtr->valueSminwaterE;
        GIZWITS_LOG("Evt: EVENT_SminwaterE %d \n", currentDataPoint.valueSminwaterE);
        if(0x01 == currentDataPoint.valueSminwaterE)
        {
         if(waterstate-1<=0)
					waterstate=1;
				else
					waterstate--; //user handle
        }
        else
        {
          if(waterstate-1<=0)
					waterstate=1;
				else
					waterstate--;//user handle    
        }
        break;
      case EVENT_MODSPEED:
        currentDataPoint.valueMODSPEED = dataPointPtr->valueMODSPEED;
        GIZWITS_LOG("Evt:EVENT_MODSPEED %d\n",currentDataPoint.valueMODSPEED);
        //user handle
        break;
      case EVENT_MODTEMP:
        currentDataPoint.valueMODTEMP = dataPointPtr->valueMODTEMP;
        GIZWITS_LOG("Evt:EVENT_MODTEMP %d\n",currentDataPoint.valueMODTEMP);
        //user handle
        break;
      case EVENT_MODMIAN:
        currentDataPoint.valueMODMIAN = dataPointPtr->valueMODMIAN;
        GIZWITS_LOG("Evt:EVENT_MODMIAN %d\n",currentDataPoint.valueMODMIAN);
        //user handle
        break;
      case EVENT_MODSHUI:
        currentDataPoint.valueMODSHUI = dataPointPtr->valueMODSHUI;
        GIZWITS_LOG("Evt:EVENT_MODSHUI %d\n",currentDataPoint.valueMODSHUI);
        //user handle
        break;
      case EVENT_MODTIME:
        currentDataPoint.valueMODTIME = dataPointPtr->valueMODTIME;
        GIZWITS_LOG("Evt:EVENT_MODTIME %d\n",currentDataPoint.valueMODTIME);
        //user handle
        break;
      case EVENT_MYTIME:
        currentDataPoint.valueMYTIME = dataPointPtr->valueMYTIME;
        GIZWITS_LOG("Evt:EVENT_MYTIME %d\n",currentDataPoint.valueMYTIME);
        //user handle
        break;
      case EVENT_MYSPEED:
        currentDataPoint.valueMYSPEED = dataPointPtr->valueMYSPEED;
        GIZWITS_LOG("Evt:EVENT_MYSPEED %d\n",currentDataPoint.valueMYSPEED);
        //user handle
        break;


      case WIFI_SOFTAP:
        break;
      case WIFI_AIRLINK:
        break;
      case WIFI_STATION:
        break;
      case WIFI_CON_ROUTER:
 
        break;
      case WIFI_DISCON_ROUTER:
 
        break;
      case WIFI_CON_M2M:
 
        break;
      case WIFI_DISCON_M2M:
        break;
      case WIFI_RSSI:
        GIZWITS_LOG("RSSI %d\n", wifiData->rssi);
        break;
      case TRANSPARENT_DATA:
        GIZWITS_LOG("TRANSPARENT_DATA \n");
        //user handle , Fetch data from [data] , size is [len]
        break;
      case WIFI_NTP:
        GIZWITS_LOG("WIFI_NTP : [%d-%d-%d %02d:%02d:%02d][%d] \n",ptime->year,ptime->month,ptime->day,ptime->hour,ptime->minute,ptime->second,ptime->ntp);
        break;
      case MODULE_INFO:
            GIZWITS_LOG("MODULE INFO ...\n");
      #if MODULE_TYPE
            GIZWITS_LOG("GPRS MODULE ...\n");
            //Format By gprsInfo_t
      #else
            GIZWITS_LOG("WIF MODULE ...\n");
            //Format By moduleInfo_t
            GIZWITS_LOG("moduleType : [%d] \n",ptModuleInfo->moduleType);
      #endif
    break;
      default:
        break;
    }
  }

  return 0;
}

/**
* User data acquisition

* Here users need to achieve in addition to data points other than the collection of data collection, can be self-defined acquisition frequency and design data filtering algorithm

* @param none
* @return none
*/
void userHandle(void)
{
 /*
    currentDataPoint.valueOnline = ;//Add Sensor Data Collection
    currentDataPoint.valuefire = ;//Add Sensor Data Collection
    currentDataPoint.valueSTATE = ;//Add Sensor Data Collection
    currentDataPoint.valuekind = ;//Add Sensor Data Collection
    currentDataPoint.valuewan = ;//Add Sensor Data Collection
    currentDataPoint.valueMODSPEEDREAD = ;//Add Sensor Data Collection
    currentDataPoint.valueMODMIANREAD = ;//Add Sensor Data Collection
    currentDataPoint.valueMODSHUIREAD = ;//Add Sensor Data Collection
    currentDataPoint.valuehetime = ;//Add Sensor Data Collection
    currentDataPoint.valueyatime = ;//Add Sensor Data Collection

    */
    
}

/**
* Data point initialization function

* In the function to complete the initial user-related data
* @param none
* @return none
* @note The developer can add a data point state initialization value within this function
*/
void userInit(void)
{
    memset((uint8_t*)&currentDataPoint, 0, sizeof(dataPoint_t));
    
    /** Warning !!! DataPoint Variables Init , Must Within The Data Range **/ 
    /*
      currentDataPoint.valueLED1 = ;
      currentDataPoint.valueLED2 = ;
      currentDataPoint.valueLED3 = ;
      currentDataPoint.valueSheE = ;
      currentDataPoint.valueSyaE = ;
      currentDataPoint.valueSonestartE = ;
      currentDataPoint.valueSkindE = ;
      currentDataPoint.valueSwindowE = ;
      currentDataPoint.valueSautoE = ;
      currentDataPoint.valueSaustartE = ;
      currentDataPoint.valueSonlystartE = ;
      currentDataPoint.valueSaustopE = ;
      currentDataPoint.valueSaurestE = ;
      currentDataPoint.valueSmanualE = ;
      currentDataPoint.valueScloseautoE = ;
      currentDataPoint.valueSmodifyE = ;
      currentDataPoint.valueSrestE = ;
      currentDataPoint.valueSmstartE = ;
      currentDataPoint.valueSmstopE = ;
      currentDataPoint.valueStstartE = ;
      currentDataPoint.valueStstopE = ;
      currentDataPoint.valueSwstartE = ;
      currentDataPoint.valueSwstopE = ;
      currentDataPoint.valueStimejE = ;
      currentDataPoint.valueStimejiE = ;
      currentDataPoint.valueSspeedjE = ;
      currentDataPoint.valueSspeedjiE = ;
      currentDataPoint.valueStempjE = ;
      currentDataPoint.valueStempjiE = ;
      currentDataPoint.valueSmaxmianE = ;
      currentDataPoint.valueSminmianE = ;
      currentDataPoint.valueSautimejE = ;
      currentDataPoint.valueSautimejiE = ;
      currentDataPoint.valueSauspeedjE = ;
      currentDataPoint.valueSauspeedjiE = ;
      currentDataPoint.valueSmensureE = ;
      currentDataPoint.valueSyautoE = ;
      currentDataPoint.valueSycloseautoE = ;
      currentDataPoint.valueSymanualE = ;
      currentDataPoint.valueSymodifyE = ;
      currentDataPoint.valueSyrestE = ;
      currentDataPoint.valueSyaustartE = ;
      currentDataPoint.valueSyaustopE = ;
      currentDataPoint.valueSyaurestE = ;
      currentDataPoint.valueSymstartE = ;
      currentDataPoint.valueSymstopE = ;
      currentDataPoint.valueSyspeedjE = ;
      currentDataPoint.valueSyspeedjiE = ;
      currentDataPoint.valueSyautimejE = ;
      currentDataPoint.valueSyautimejiE = ;
      currentDataPoint.valueSyauspeedjE = ;
      currentDataPoint.valueSyauspeedjiE = ;
      currentDataPoint.valueSymensureE = ;
      currentDataPoint.valueSmaxwaterE = ;
      currentDataPoint.valueSminwaterE = ;
      currentDataPoint.valueMODSPEED = ;
      currentDataPoint.valueMODTEMP = ;
      currentDataPoint.valueMODMIAN = ;
      currentDataPoint.valueMODSHUI = ;
      currentDataPoint.valueMODTIME = ;
      currentDataPoint.valueMYTIME = ;
      currentDataPoint.valueMYSPEED = ;
      currentDataPoint.valueOnline = ;
      currentDataPoint.valuefire = ;
      currentDataPoint.valueSTATE = ;
      currentDataPoint.valuekind = ;
      currentDataPoint.valuewan = ;
      currentDataPoint.valueMODSPEEDREAD = ;
      currentDataPoint.valueMODMIANREAD = ;
      currentDataPoint.valueMODSHUIREAD = ;
      currentDataPoint.valuehetime = ;
      currentDataPoint.valueyatime = ;
    */

}


/**
* @brief Millisecond timing maintenance function, milliseconds increment, overflow to zero

* @param none
* @return none
*/
void gizTimerMs(void)
{
    timerMsCount++;
}

/**
* @brief Read millisecond count

* @param none
* @return millisecond count
*/
uint32_t gizGetTimerCount(void)
{
    return timerMsCount;
}

/**
* @brief MCU reset function

* @param none
* @return none
*/
void mcuRestart(void)
{
    __set_FAULTMASK(1);
   // HAL_NVIC_SystemReset();
}

/**@} */

#ifdef __GNUC__
  /* With GCC/RAISONANCE, small printf (option LD Linker->Libraries->Small printf
     set to 'Yes') calls __io_putchar() */
  #define PUTCHAR_PROTOTYPE int __io_putchar(int ch)
#else
  #define PUTCHAR_PROTOTYPE int fputc(int ch, FILE *f)
#endif /* __GNUC__ */
/**
  * @brief  Retargets the C library printf function to the USART.
  * @param  None
  * @retval None
  */
PUTCHAR_PROTOTYPE
{
  /* Place your implementation of fputc here */
  /* e.g. write a character to the USART1 and Loop until the end of transmission */
//  HAL_UART_Transmit(&huart1, (uint8_t *)&ch, 1, 0xFFFF);
 
  return ch;
}

/**
  * @brief  Period elapsed callback in non blocking mode 
  * @param  htim : TIM handle
  * @retval None
  */
void HAL_TIM_PeriodElapsedCallback(void)
{

}

/**
* @brief Timer TIM3 init function

* @param none
* @return none
*/
void timerInit(void)
{
	
}

/**
  * @brief  This function handles USART IDLE interrupt.
  */
void HAL_UART_RxCpltCallback()  
{  
   
}  

/**
* @brief USART init function

* Serial communication between WiFi modules and device MCU
* @param none
* @return none
*/
void uartInit(void)
{
	//HAL_UART_Receive_IT(&huart2, (uint8_t *)&aRxBuffer, 1);//开启下一次接收中断  
}

/**
* @brief Serial port write operation, send data to WiFi module
*
* @param buf      : buf address
* @param len      : buf length
*
* @return : Return effective data length;-1，return failure
*/
int32_t uartWrite(uint8_t *buf, uint32_t len)
{
		uint8_t crc[1] = {0x55};
    uint32_t i = 0;
	
    if(NULL == buf)
    {
        return -1;
    }

    for(i=0; i<len; i++)
    {
				uart3SendChar(buf[i]);
       // HAL_UART_Transmit_IT(&huart2, (uint8_t *)&buf[i], 1);
				//while (huart2.gState != HAL_UART_STATE_READY);//Loop until the end of transmission

        if(i >=2 && buf[i] == 0xFF)
        {
					uart3SendChar(0x55);
					//	HAL_UART_Transmit_IT(&huart2, (uint8_t *)&crc, 1);
					//	while (huart2.gState != HAL_UART_STATE_READY);//Loop until the end of transmission
        }
    }

#ifdef PROTOCOL_DEBUG
    GIZWITS_LOG("MCU2WiFi[%4d:%4d]: ", gizGetTimerCount(), len);
    for(i=0; i<len; i++)
    {
        GIZWITS_LOG("%02x ", buf[i]);

        if(i >=2 && buf[i] == 0xFF)
        {
            GIZWITS_LOG("%02x ", 0x55);
        }
    }
    GIZWITS_LOG("\n");
#endif
		
		return len;
}  
